package com.gitee.ywj1352.nio;

import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

public class NioService {

    private int port = 8090;

    public InetSocketAddress inetSocketAddress;


    public NioService(int port){

        try {
            this.port = port;
            inetSocketAddress = new InetSocketAddress(port);

            ServerSocketChannel channel = ServerSocketChannel.open();

            Selector selector = Selector.open();

            channel.configureBlocking(false);

            channel.socket().bind(inetSocketAddress);

            channel.register(selector, SelectionKey.OP_ACCEPT);
            System.out.println("服务启动成功");
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        NioService nioService = new NioService(8090);


    }


}
